package com.aoxiang.earlywaringapi.vo;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import lombok.ToString;
import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;

/**
 * @author teevil@126.com
 * @date 2021/6/28
 */
@ToString
@SuppressWarnings("unchecked")
public class PagingCopyVO<T, E> extends PagingVO {
    public PagingCopyVO(Page<T> pageT, Class<E> eClass) {
        this.initPageParameters(pageT);
        List<T> tList = pageT.getContent();
        Mapper mapper = DozerBeanMapperBuilder.buildDefault();
        List<E> kList = new ArrayList<>();
        tList.forEach(t -> {
            E vo = mapper.map(t, eClass);
            kList.add(vo);
        });
        this.setItems(kList);
    }
}